<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <title>个人信息管理</title>
    </head>
    <body>
        <div id="form_base_info">
        </div>
        <script>
            Ext.onReady(function(){
                /*
                 * Ext.ux.ItemSelector Example Code
                 */
                tabs.getActiveTab().setTitle('个人信息管理');
                var userName = new Ext.form.TextField({
                    fieldLabel: '姓名',
                    allowBlank: false,
                    name: 'user_name',
                    anchor: '90%'
                });
                
                var sexMale = new Ext.form.Radio({
                    fieldLabel: '性别',
                    name: 'sex',
                    id: 'sex_male',
                    boxLabel: '男',
                    checked: true,
                    inputValue: '男'
                });
                var sexFemale = new Ext.form.Radio({
                    name: 'sex',
                    id: 'sex_female',
                    boxLabel: '女',
                    checked: false,
                    hideLabel: true,
                    inputValue: '女'
                });
                
                var phone = new Ext.form.TextField({
                    fieldLabel: '个人电话',
                    allowBlank: false,
                    name: 'phone',
                    anchor: '90%'
                });
                
                var email = new Ext.form.TextField({
                    fieldLabel: '电子邮件',
                    allowBlank: false,
                    name: 'email',
                    vtype: 'email',
                    anchor: '90%'
                });
                
                var card = new Ext.form.TextField({
                    fieldLabel: '身份证',
                    allowBlank: false,
                    name: 'card',
                    anchor: '90%'
                });
                
                var companyName = new Ext.form.TextField({
                    fieldLabel: '公司名称',
                    allowBlank: false,
                    name: 'company_name',
                    anchor: '90%'
                });
                
                var companyPhone = new Ext.form.TextField({
                    fieldLabel: '公司电话',
                    allowBlank: false,
                    name: 'company_phone',
                    anchor: '90%'
                });
                
                var companyFax = new Ext.form.TextField({
                    fieldLabel: '公司传真',
                    allowBlank: false,
                    name: 'company_fax',
                    anchor: '90%'
                });
                
                var address = new Ext.form.TextField({
                    fieldLabel: '公司地址',
                    allowBlank: false,
                    name: 'address',
                    anchor: '90%'
                });
                
                var postCode = new Ext.form.TextField({
                    fieldLabel: '公司邮编',
                    allowBlank: false,
                    name: 'post_code',
                    anchor: '90%'
                });
                
                var formBaseInfo = new Ext.form.FormPanel({
                    labelWidth: 80,
                    frame: true,
                    labelAlign: 'right',
                    width: 550,
                    url: '/web_user/setBaseInfo',
					reader: new Ext.data.JsonReader({
                        root: 'root'
                    }, [{
                        name: 'user_name'
                    }, {
                        name: 'sex'
                    }, {
                        name: 'phone'
                    }, {
                        name: 'email'
                    }, {
                        name: 'card'
                    }, {
                        name: 'address'
                    }, {
                        name: 'company_name'
                    }, {
                        name: 'company_phone'
                    }, {
                        name: 'company_fax'
                    }, {
                        name: 'post_code'
                    }]),
                    items: [userName, {
                        layout: 'column',
                        border: false,
                        items: [{
                            columnWidth: .25,
                            layout: 'form',
                            border: false,
                            items: [sexMale]
                        }, {
                            columnWidth: .25,
                            layout: 'form',
                            border: false,
                            items: [sexFemale]
                        }]
                    }, email, phone, card, companyName, companyPhone, companyFax, address, postCode],
                    buttons: [{
                        text: '确定',
                        handler: onItemClick //实际应用一般是处理fp.getForm.submit()事件   
                    }, {
                        text: '帮助',
                        handler: function(){
                            formBaseInfo.getForm().reset();
                        }
                    }]
                });
                formBaseInfo.render("form_base_info");
                function onItemClick(item){
                    if (formBaseInfo.form.isValid()) {
                        formBaseInfo.form.submit({
                            waitMsg: '正在提交......',
                            success: function(form, action){
                                Ext.MessageBox.alert("提示", "基本信息保存成功！");
                            },
                            failure: function(form, action){
                                Ext.MessageBox.alert('提交错误消息', '提交失败');
                            }
                        });
                    }
                    else {
                        Ext.MessageBox.alert("提示", "请按要求填写带<span class='red'>*</span>的必输值！");
                    }
                }
				
				// load form and assign value to fields
                formBaseInfo.form.load({
                    url: '/web_user/getBaseInfoByID?id=<%=session[:web_user_id]%>',
                    waitMsg: '正在载入数据...',
                    success: function(form, action){
                    },
                    failure: function(form, action){
                        Ext.MessageBox.alert('提示信息', '信息加载失败');
                    }
                });
            })
        </script>
    </body>
</html>
